// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLPartitionSpec.h"
#include "../visitor/SQLASTVisitor.h"
#include "../../utils/listTran.h"
#include "SQLName.h"

// @Override
void SQLPartitionSpec_Item::accept0(SQLASTVisitor_ptr v)
{
  if (v->visit(SharedObject(SQLPartitionSpec_Item)))
  {
    acceptChild(v, column);
    acceptChild(v, value);
  }
  v->endVisit(SharedObject(SQLPartitionSpec_Item));
}

SQLObject_ptr SQLPartitionSpec_Item::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLPartitionSpec_Item>(new SQLPartitionSpec_Item());
  std::shared_ptr<SQLPartitionSpec_Item> x = std::dynamic_pointer_cast<SQLPartitionSpec_Item>(clone_tmp);
  // Item x = new Item();

  if (column != nullptr)
  {
    x->setColumn(std::dynamic_pointer_cast<SQLName>(column->clone()));
  }

  if (value != nullptr)
  {
    x->setValue(std::dynamic_pointer_cast<SQLExpr>(value->clone()));
  }

  return x;
}

SQLName_ptr SQLPartitionSpec_Item::getColumn()
{
  return column;
}

void SQLPartitionSpec_Item::setColumn(SQLName_ptr column)
{
  this->column = column;
}

SQLExpr_ptr SQLPartitionSpec_Item::getValue()
{
  return value;
}

void SQLPartitionSpec_Item::setValue(SQLExpr_ptr value)
{
  this->value = value;
}

SQLPartitionSpec::SQLPartitionSpec()
{
  items = std::make_shared<std::list<SQLPartitionSpec_Item_ptr>>();
}
// @Override
void SQLPartitionSpec::accept0(SQLASTVisitor_ptr v)
{
  if (v->visit(SharedObject(SQLPartitionSpec)))
  {
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLPartitionSpec_Item, SQLObject>(items);
    acceptChild(v, tmp);
  }
  v->endVisit(SharedObject(SQLPartitionSpec));
}

void SQLPartitionSpec::addItem(SQLPartitionSpec_Item_ptr item)
{
  item->setParent(SharedObject(SQLPartitionSpec));
  items->push_back(item);
}

SQLPartitionSpec_Item_list_ptr SQLPartitionSpec::getItems()
{
  return items;
}

SQLObject_ptr SQLPartitionSpec::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLPartitionSpec>(new SQLPartitionSpec());
  std::shared_ptr<SQLPartitionSpec> x = std::dynamic_pointer_cast<SQLPartitionSpec>(clone_tmp);
  // SQLPartitionSpec x = new SQLPartitionSpec();

  for (SQLPartitionSpec_Item_ptr item : *items)
  {
    x->addItem(std::dynamic_pointer_cast<SQLPartitionSpec_Item>(item->clone()));
  }

  return x;
}
